#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import shutil
import sys

execfile(os.path.join(sys.path[0], "framework.py"))

from oriolusdocker.docker import DockerFactory, DockerError
from oriolusdocker.storages.memorystorage import MemoryStorage
from oriolusgaffer.cache import Cache
from oriolusgaffer.gaffer.selectstrategy import LatestStrategy
from oriolusgaffer.gaffer.catalogue import Catalogue
from oriolusgaffer.gaffer import Gaffer, GafferError
from orioluspith.packets.meta import Meta
from orioluspith.packets.packet import Packet, Status
from pmock import *
from unittest import TestCase, TestLoader, TextTestRunner
from test_gaffer import TestGaffer

class TestInstall(TestGaffer):
    def setUp(self):
        self.__test_packets_path = os.path.join(os.getcwd(), "testdata", "testpackets")

        self.__cache_path = os.path.join(os.getcwd(), "testdata", "gaffer_cache")
        self.__temp_dirs = (self.__cache_path, )

        self.__setup_mocks()

    def tearDown(self):
        for path in self.__temp_dirs:
            if os.path.exists(path):
                shutil.rmtree(path)
                
    def test_install01(self):    
        """
        Packet - packet_a-1.2.3.4 will be installed.
        without dependencies, replaces and conflicts.
        """    
        
        packet_folder = "test_install01"
        packet_name_a = "packet_a-1.2.3.4"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        
        trotter_packet_list = [packet_name_a,]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))
        
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))        
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        
        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",

                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install02(self):
        """
        Packet - packet_b-1.2.3.4 will be installed.
        packet_a-1.2.3.4 depends on packet_b-1.2.3.4
        """
        
        packet_folder = "test_install02"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-1.2.3.4"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        
        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-1.2.3.4"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))
        
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))        
  
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("1.2.3.4")).will(return_value(packet_path_b))
        
        packets_to_install = ("packet_b-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",

                                   "search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))",
                                   "install(packet_path=string_contains('packet_b-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install03(self):
        """
        Packet - packet_a-1.2.3.4 will be installed.
        Packet - packet_b-1.2.3.4 will be installed.        
        packet_a-1.2.3.4 depends on packet_b-1.2.3.4
        """
                
        packet_folder = "test_install03"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-1.2.3.4"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        
        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-1.2.3.4"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))
                 
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["1.2.3.4"]))
  
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("1.2.3.4")).will(return_value(packet_path_b))
        
        packets_to_install = ("packet_a-1.2.3.4", "packet_b-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",

                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))",
                                   "search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))",
                                   "install(packet_path=string_contains('packet_b-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install04(self):
        """
        Packet - packet_a-1.2.3.4 will be installed.
        Packet - packet_b-1.2.3.4 will be installed.        
        packet_a-1.2.3.4 depends on packet_b-1.2.3.4
        """
                
        packet_folder = "test_install04"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-1.2.3.4"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        
        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-1.2.3.4"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))         
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["1.2.3.4"]))
  
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("1.2.3.4")).will(return_value(packet_path_b))
        
        packets_to_install = ("packet_b-1.2.3.4", "packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",

                                   "search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))",
                                   "install(packet_path=string_contains('packet_b-1.2.3.4'))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))")

        self.assert_install(packets_to_install, expected_actions)

    def test_install05(self):
        """
        Packet - packet_a-1.2.3.4 will be installed.
        Packet - packet_a2-1.2.3.4 will be installed.
        """
        
        packet_folder = "test_install05"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-1.2.3.4"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        
        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-1.2.3.4"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))         
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["1.2.3.4"]))
  
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("1.2.3.4")).will(return_value(packet_path_b))
        
        packets_to_install = ("packet", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",

                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))",
                                   "search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))",
                                   "install(packet_path=string_contains('packet_b-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install06(self):
        """
        Packet - packet_a-1.2.3.4 will not be installed.
        It's in the repository already.
        """
        
        packet_folder = "test_install06"
        packet_name_a = "packet_a-1.2.3.4"                
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        
        trotter_packet_list = ["packet_a-1.2.3.4"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))         
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))        
  
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))  
        
        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))",

                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install07(self):
        """
        Packet - packet_a-1.2.3.4 will be installed.
        Packet - packet_b-1.2.3.4 will be installed.        
        packet_a-1.2.3.4 depends on packet_b-1.2.3.4
        """        
        packet_folder = "test_install04"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-1.2.3.4"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        
        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-1.2.3.4"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))         
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["1.2.3.4"]))
  
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("1.2.3.4")).will(return_value(packet_path_b))
        
        packets_to_install = ("packet_a-1.2.3.4", "packet_b-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))",
                                   "search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))",

                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))",
                                   "search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))",
                                   "install(packet_path=string_contains('packet_b-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install08(self):
        """
        Packet - packet_a-1.2.3.4 will be installed.
        Packet - packet_b-1.2.3.4 will be installed.        
        packet_a-1.2.3.4 depends on packet_b-1.2.3.4
        """        
        packet_folder = "test_install08"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-1.2.3.4"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        
        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-1.2.3.4"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))         
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["1.2.3.4"]))
  
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("1.2.3.4")).will(return_value(packet_path_b))
        
        packets_to_install = ("packet_a-1.2.3.4", "packet_b-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))",
                                   "search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))",

                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))",
                                   "search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install09(self):
        """
        Packet - packet_a-1.2.3.4 will be installed.
        Packet - packet_b-1.2.3.4 will be installed.        
        packet_a-1.2.3.4 depends on packet_b-1.2.3.4
        """        
        
        packet_folder = "test_install09"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-1.2.3.4"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        
        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-1.2.3.4"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))         
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["1.2.3.4"]))
  
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("1.2.3.4")).will(return_value(packet_path_b))
        
        packets_to_install = ("packet_b-1.2.3.4", "packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))",

                                   "search(full_name=eq('packet_b-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([object()]))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install10(self):
        """
        Packet - packet_a-1.2.3.4 will be installed.
        Packet - packet_b-2.3.4.5 will not be replaced.        
        Trotter list: packet_a-1.2.3.4, packet_b-1.2.3.4
        
        packet_a-1.2.3.4 replaces packet_b-2.3.4.5
        """
        
        packet_folder = "test_install10"
        packet_name_a = "packet_a-1.2.3.4"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-1.2.3.4"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))        
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        
        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_b'), status=eq(Status.INSTALLED)).will(return_value([]))",

                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install11(self):
        """
        Packet - packet_a-1.2.3.4 will be installed.
        Packet - packet_b-2.3.4.5 will be replaced.        
        Trotter list: packet_a-1.2.3.4, packet_b-1.2.3.4
        
        packet_a-1.2.3.4 replacets packet_b-2.3.4.5
        """
        packet_folder = "test_install11"
        packet_name_a = "packet_a-1.2.3.4"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-1.2.3.4"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))        
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        
        self.__storage.add(Packet(Meta("packet_b", "2.3.4.5", None, [], [], [])))
        
        packets_to_install = ("packet_a-1.2.3.4", )        
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_b'), status=eq(Status.INSTALLED)).will(return_value([Packet(Meta('packet_b', '2.3.4.5', None, [], [], []))]))",

                                   "remove(eq('packet_b-2.3.4.5'))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install12(self):
        """
        Packet - packet_a-1.2.3.4 will not be installed.             
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5
        
        packet_a-1.2.3.4 conflicts with packet_b-2.3.4.5
        packet_b-2.3.4.5 is installed
        """
        packet_folder = "test_install12"
        packet_name_a = "packet_a-1.2.3.4"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))        
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        
        self.__storage.add(Packet(Meta("packet_b", "2.3.4.5", None, [], [], [])))

        packets_to_install = ("packet_a-1.2.3.4", )        
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))", )

        self.assert_install_fail(packets_to_install, expected_actions)

    def test_install13(self):
        """
        Packet - packet_a-1.2.3.4 will be installed.             
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5
        
        packet_a-1.2.3.4 conflicts with packet_b-2.3.4.5
        packet_b-2.3.4.5 is not installed
        """
        packet_folder = "test_install13"
        packet_name_a = "packet_a-1.2.3.4"                
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))        
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        
        packets_to_install = ("packet_a-1.2.3.4", )        
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",

                               "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                               "install(packet_path=string_contains('packet_a-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install14(self):
        """
        Packet - packet_a-1.2.3.4 will be installed.             
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6
        
        packet_a-1.2.3.4 depends on packet_b-2.3.4.5 and packet_c-3.4.5.6
        packet_b-2.3.4.5 conflicts with packet_c-3.4.5.6
        """
        packet_folder = "test_install14"
        packet_name_a = "packet_a-1.2.3.4"                
        packet_name_b = "packet_b-2.3.4.5"        
        packet_name_c = "packet_c-3.4.5.6"        
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        packet_path_c = self.__get_packet_path(packet_folder, packet_name_c)
        
        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))         
        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["2.3.4.5"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_c")).will(return_value(["3.4.5.6"]))
  
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_c"), eq("3.4.5.6")).will(return_value(packet_path_c))
        
        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))", )

        self.assert_install_fail(packets_to_install, expected_actions)

    def test_install15(self):
        """
        Packet - packet_a-1.2.3.4 will be installed.             
        Packet - packet_c-3.4.5.6 will be installed.
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6
        
        packet_a-1.2.3.4 depends on packet_c-3.4.5.6
        packet_a-1.2.3.4 replaces packet_b-2.3.4.5
        packet_b-2.3.4.5 is installed
        """
        packet_folder = "test_install15"
        packet_name_a = "packet_a-1.2.3.4"                
        packet_name_b = "packet_b-2.3.4.5"        
        packet_name_c = "packet_c-3.4.5.6"        
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        packet_path_c = self.__get_packet_path(packet_folder, packet_name_c)
        
        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))
                         
        self.__mock_trotter.stubs().get_versions(eq("packet_c")).will(return_value(["3.4.5.6"]))
  
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))        
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_c"), eq("3.4.5.6")).will(return_value(packet_path_c))

        self.__storage.add(Packet(Meta("packet_b", "2.3.4.5", None, [], [], [])))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_b'), status=eq(Status.INSTALLED)).will(return_value([Packet(Meta('packet_b', '2.3.4.5', None, [], [], []))]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",

                                   "remove(eq('packet_b-2.3.4.5'))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_c-3.4.5.6'))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install16(self):
        """
        Packet - packet_a-1.2.3.4 will not be installed.
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6
        
        packet_a-1.2.3.4 replaces packet_b-2.3.4.5
        packet_a-1.2.3.4 conflicts with packet_c-3.4.5.6
        packet_b-2.3.4.5 is installed
        packet_c-2.3.4.5 is installed
        """
        
        packet_folder = "test_install16"
        packet_name_a = "packet_a-1.2.3.4"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
                  
        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
                
        self.__storage.add(Packet(Meta("packet_b", "2.3.4.5", None, [], [], [])))
        self.__storage.add(Packet(Meta("packet_c", "3.4.5.6", None, [], [], [])))        

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_b'), status=eq(Status.INSTALLED)).will(return_value([Packet(Meta('packet_b', '2.3.4.5', None, [], [], []))]))", )
      
        self.assert_install_fail(packets_to_install, expected_actions)

    def test_install17(self):
        """
        Packet - packet_a-1.2.3.4 will not be installed.
        Packet - packet_b-2.3.4.5 will not be installed.
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6
        
        packet_a-1.2.3.4 depends on packet_b-2.3.4.5
        packet_a-1.2.3.4 conflicts with packet_c-3.4.5.6
        
        packet_c-2.3.4.5 is installed
        """
      
        packet_folder = "test_install17"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        
        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))
        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["2.3.4.5"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))

        self.__storage.add(Packet(Meta("packet_c", "3.4.5.6", None, [], [], [])))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))", )
        
        self.assert_install_fail(packets_to_install, expected_actions)

    def test_install18(self):
        """
        Packet - packet_a-1.2.3.4 will not be installed.        
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6
        
        packet_a-1.2.3.4 depends on packet_b-2.3.4.5
        packet_a-1.2.3.4 depends on packet_c-3.4.5.6
        packet_b-2.3.4.5 replaces packet_c-3.4.5.6
        
        packet_c-2.3.4.5 is installed
        """
        
        packet_folder = "test_install18"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_name_c = "packet_c-3.4.5.6"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        packet_path_c = self.__get_packet_path(packet_folder, packet_name_c)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))
        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["2.3.4.5"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_c")).will(return_value(["3.4.5.6"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_c"), eq("3.4.5.6")).will(return_value(packet_path_c))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_c'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))", )

        self.assert_install_fail(packets_to_install, expected_actions)

    def test_install19(self):
        """
        Packet - packet_a-1.2.3.4 will not be installed.        
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6
        
        packet_a-1.2.3.4 depends on packet_b-2.3.4.5
        packet_a-1.2.3.4 depends on packet_c-3.4.5.6
        packet_b-2.3.4.5 conflicts with packet_c-3.4.5.6
        """

        packet_folder = "test_install19"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_name_c = "packet_c-3.4.5.6"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        packet_path_c = self.__get_packet_path(packet_folder, packet_name_c)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))

        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["2.3.4.5"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_c")).will(return_value(["3.4.5.6"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_c"), eq("3.4.5.6")).will(return_value(packet_path_c))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))", )

        self.assert_install_fail(packets_to_install, expected_actions)

    def test_install20(self):
        """
        Packet - packet_a-1.2.3.4 will not be installed.        
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6
        
        packet_a-1.2.3.4 depends on packet_b-2.3.4.5
        packet_a-1.2.3.4 depends on packet_c-3.4.5.6
        packet_c-3.4.5.6 replaces packet_b-2.3.4.5
        """

        packet_folder = "test_install20"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_name_c = "packet_c-3.4.5.6"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        packet_path_c = self.__get_packet_path(packet_folder, packet_name_c)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))

        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["2.3.4.5"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_c")).will(return_value(["3.4.5.6"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_c"), eq("3.4.5.6")).will(return_value(packet_path_c))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_b'), status=eq(Status.INSTALLED)).will(return_value([]))", )

        self.assert_install_fail(packets_to_install, expected_actions)

    def test_install21(self):
        """
        Packet - packet_a-1.2.3.4 will not be installed.        
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6, packet_d-4.5.6.7
        
        packet_a-1.2.3.4 depends on packet_b-2.3.4.5
        packet_a-1.2.3.4 depends on packet_c-3.4.5.6
        packet_b-3.4.5.6 conflicts with packet_d-4.5.6.7
        packet_c-3.4.5.6 depends on packet_d-4.5.6.7
        """
        
        packet_folder = "test_install21"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_name_c = "packet_c-3.4.5.6"
        packet_name_d = "packet_d-4.5.6.7"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        packet_path_c = self.__get_packet_path(packet_folder, packet_name_c)
        packet_path_d = self.__get_packet_path(packet_folder, packet_name_d)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6", "packet_d-4.5.6.7"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))

        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["2.3.4.5"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_c")).will(return_value(["3.4.5.6"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_d")).will(return_value(["4.5.6.7"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_c"), eq("3.4.5.6")).will(return_value(packet_path_c))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_d"), eq("4.5.6.7")).will(return_value(packet_path_d))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_d-4.5.6.7'), status=eq(Status.INSTALLED)).will(return_value([]))", )

        self.assert_install_fail(packets_to_install, expected_actions)

    def test_install22(self):
        """
        Packet - packet_a-1.2.3.4 will not be installed.        
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6, packet_d-4.5.6.7
        
        packet_a-1.2.3.4 depends on packet_b-2.3.4.5
        packet_a-1.2.3.4 depends on packet_c-3.4.5.6
        packet_b-3.4.5.6 replace packet_d-4.5.6.7
        packet_c-3.4.5.6 depends on packet_d-4.5.6.7
        """
        
        packet_folder = "test_install22"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_name_c = "packet_c-3.4.5.6"
        packet_name_d = "packet_d-4.5.6.7"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        packet_path_c = self.__get_packet_path(packet_folder, packet_name_c)
        packet_path_d = self.__get_packet_path(packet_folder, packet_name_d)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6", "packet_d-4.5.6.7"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))

        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["2.3.4.5"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_c")).will(return_value(["3.4.5.6"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_d")).will(return_value(["4.5.6.7"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_c"), eq("3.4.5.6")).will(return_value(packet_path_c))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_d"), eq("4.5.6.7")).will(return_value(packet_path_d))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_d'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_d-4.5.6.7'), status=eq(Status.INSTALLED)).will(return_value([]))", )

        self.assert_install_fail(packets_to_install, expected_actions)

    def test_install23(self):
        """
        Packet - packet_a-1.2.3.4 will not be installed.        
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6, packet_d-4.5.6.7
        
        packet_a-1.2.3.4 depends on packet_b-2.3.4.5
        packet_a-1.2.3.4 depends on packet_c-3.4.5.6
        packet_b-3.4.5.6 replace packet_d-4.5.6.7
        packet_c-3.4.5.6 depends on packet_d-4.5.6.7
        
        packet_d-4.5.6.7 is installed
        """
        
        packet_folder = "test_install23"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_name_c = "packet_c-3.4.5.6"
        packet_name_d = "packet_d-4.5.6.7"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        packet_path_c = self.__get_packet_path(packet_folder, packet_name_c)
        packet_path_d = self.__get_packet_path(packet_folder, packet_name_d)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6", "packet_d-4.5.6.7"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))

        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["2.3.4.5"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_c")).will(return_value(["3.4.5.6"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_d")).will(return_value(["4.5.6.7"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_c"), eq("3.4.5.6")).will(return_value(packet_path_c))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_d"), eq("4.5.6.7")).will(return_value(packet_path_d))

        self.__storage.add(Packet(Meta("packet_d", "4.5.6.7", None, [], [], [])))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_d'), status=eq(Status.INSTALLED)).will(return_value([Packet(Meta('packet_d', '4.5.6.7', None, [], [], []))]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_d-4.5.6.7'), status=eq(Status.INSTALLED)).will(return_value([object()]))", )

        self.assert_install_fail(packets_to_install, expected_actions)

    def test_install24  (self):
        """
        Packet - packet_a-1.2.3.4 will be installed. Packet_b-2.3.4.5 and packet_c-3.4.5.6 will be installed too.        
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6, packet_d-4.5.6.7
        
        packet_a-1.2.3.4 depends on packet_b-2.3.4.5
        packet_a-1.2.3.4 depends on packet_c-3.4.5.6
        packet_b-2.3.4.5 replace packet_d-4.5.6.7
        
        packet_d-4.5.6.7 is installed
        """
        
        packet_folder = "test_install24"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_name_c = "packet_c-3.4.5.6"
        packet_name_d = "packet_d-4.5.6.7"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        packet_path_c = self.__get_packet_path(packet_folder, packet_name_c)
        packet_path_d = self.__get_packet_path(packet_folder, packet_name_d)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6", "packet_d-4.5.6.7"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))

        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["2.3.4.5"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_c")).will(return_value(["3.4.5.6"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_c"), eq("3.4.5.6")).will(return_value(packet_path_c))

        self.__storage.add(Packet(Meta("packet_d", "4.5.6.7", None, [], [], [])))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_d'), status=eq(Status.INSTALLED)).will(return_value([Packet(Meta('packet_d', '4.5.6.7', None, [], [], []))]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",

                                   "remove(eq('packet_d-4.5.6.7'))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_b-2.3.4.5'))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_c-3.4.5.6'))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install25(self):
        """
        Packet - packet_a-1.2.3.4 will be installed. Packet_b-2.3.4.5, packet_c-3.4.5.6 and packet_d-4.5.6.7 will be installed too.        
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6, packet_d-4.5.6.7
        
        packet_a-1.2.3.4 depends on packet_b-2.3.4.5
        packet_a-1.2.3.4 depends on packet_c-3.4.5.6
        packet_b-2.3.4.5 replace packet_d-[4.5.6.3, 4.5.6.6]
        packet_c-3.4.5.6 depends on packet_d-(4.5.6.4,)
        
        packet_d-4.5.6.5 is installed
        """
        
        packet_folder = "test_install25"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_name_c = "packet_c-3.4.5.6"
        packet_name_d = "packet_d-4.5.6.7"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        packet_path_c = self.__get_packet_path(packet_folder, packet_name_c)
        packet_path_d = self.__get_packet_path(packet_folder, packet_name_d)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6", "packet_d-4.5.6.5", "packet_d-4.5.6.7"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))
        
        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["2.3.4.5"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_c")).will(return_value(["3.4.5.6"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_d")).will(return_value(["4.5.6.5", "4.5.6.7"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_c"), eq("3.4.5.6")).will(return_value(packet_path_c))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_d"), eq("4.5.6.7")).will(return_value(packet_path_d))

        self.__storage.add(Packet(Meta("packet_d", "4.5.6.5", None, [], [], [])))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_d'), status=eq(Status.INSTALLED)).will(return_value([Packet(Meta('packet_d', '4.5.6.5', None, [], [], []))]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_d-4.5.6.7'), status=eq(Status.INSTALLED)).will(return_value([]))",

                                   "remove(eq('packet_d-4.5.6.5'))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_b-2.3.4.5'))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_d-4.5.6.7'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_d-4.5.6.7'))",
                                   "install(packet_path=string_contains('packet_c-3.4.5.6'))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install26(self):
        """
        Packet - packet_a-1.2.3.4 will be installed. Packet_b-2.3.4.5, packet_c-3.4.5.6 and packet_d-4.5.6.7 will be installed too.        
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6, packet_d-4.5.6.5, packet_d-4.5.6.7
        
        packet_a-1.2.3.4 depends on packet_b-2.3.4.5
        packet_a-1.2.3.4 depends on packet_c-3.4.5.6
        packet_b-2.3.4.5 depends on packet_d-4.5.6.4
        packet_c-3.4.5.6 replaces packet_d-[4.5.6.3,4.5.6.6]
        
        packet_d-4.5.6.5 is installed
        """
        
        packet_folder = "test_install26"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_name_c = "packet_c-3.4.5.6"
        packet_name_d = "packet_d-4.5.6.7"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        packet_path_c = self.__get_packet_path(packet_folder, packet_name_c)
        packet_path_d = self.__get_packet_path(packet_folder, packet_name_d)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6", "packet_d-4.5.6.5", "packet_d-4.5.6.7"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))

        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["2.3.4.5"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_c")).will(return_value(["3.4.5.6"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_d")).will(return_value(["4.5.6.5", "4.5.6.7"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_c"), eq("3.4.5.6")).will(return_value(packet_path_c))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_d"), eq("4.5.6.7")).will(return_value(packet_path_d))

        self.__storage.add(Packet(Meta("packet_d", "4.5.6.5", None, [], [], [])))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_d-4.5.6.7'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_d'), status=eq(Status.INSTALLED)).will(return_value([Packet(Meta('packet_d', '4.5.6.5', None, [], [], []))]))",

                                   "remove(eq('packet_d-4.5.6.5'))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_d-4.5.6.7'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_d-4.5.6.7'))",
                                   "install(packet_path=string_contains('packet_b-2.3.4.5'))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_c-3.4.5.6'))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install27(self):
        """
        Packet - packet_a-1.2.3.4 will be installed. Packet_b-2.3.4.5, packet_c-3.4.5.6 will be installed too.        
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6
        
        packet_a-1.2.3.4 depends on packet_b-2.3.4.5
        packet_a-1.2.3.4 depends on packet_c-3.4.5.6
        packet_b-2.3.4.5 depends on packet_c-3.4.5.6
        """
        
        packet_folder = "test_install27"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_name_c = "packet_c-3.4.5.6"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        packet_path_c = self.__get_packet_path(packet_folder, packet_name_c)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))

        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["2.3.4.5"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_c")).will(return_value(["3.4.5.6"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_c"), eq("3.4.5.6")).will(return_value(packet_path_c))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",

                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_c-3.4.5.6'))",
                                   "install(packet_path=string_contains('packet_b-2.3.4.5'))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([object()]))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install28(self):
        """
        Packet - packet_a-1.2.3.4 will be installed.        
        Trotter list: packet_a-1.2.3.4
        
        packet_a-1.2.3.4 replaces [packet_b-2.3.4.5, packet_c-3.4.5.6, packet_d-4.5.6.7]
        
        packet_b-2.3.4.5 is installed
        packet_c-3.4.5.6 is installed
        packet_d-4.5.6.5 is installed
        """
        
        packet_folder = "test_install28"
        packet_name_a = "packet_a-1.2.3.4"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)

        self.__mock_trotter.stubs().get_packet_list().will(return_value(["packet_a-1.2.3.4"]))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))

        self.__storage.add(Packet(Meta("packet_b", "2.3.4.5", None, [], [], [])))
        self.__storage.add(Packet(Meta("packet_c", "3.4.5.6", None, [], [], [{"Name": "packet_b", "Version": "2.3.4.5"}])))
        self.__storage.add(Packet(Meta("packet_d", "4.5.6.7", None, [], [], [{"Name": "packet_c", "Version": "3.4.5.6"}])))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_b'), status=eq(Status.INSTALLED)).will(return_value([Packet(Meta('packet_b', '2.3.4.5', None, [], [], []))]))",
                                   "search(name=eq('packet_c'), status=eq(Status.INSTALLED)).will(return_value([Packet(Meta('packet_c', '3.4.5.6', None, [], [], [{'Name': 'packet_b', 'Version': '2.3.4.5'}]))]))",
                                   "search(name=eq('packet_d'), status=eq(Status.INSTALLED)).will(return_value([Packet(Meta('packet_d', '4.5.6.7', None, [], [], [{'Name': 'packet_c', 'Version': '3.4.5.6'}]))]))",

                                   "remove(eq('packet_d-4.5.6.7'))",
                                   "remove(eq('packet_c-3.4.5.6'))",
                                   "remove(eq('packet_b-2.3.4.5'))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install29(self):
        """
        Packet - packet_a-1.2.3.4 will be installed. Packet_b-2.3.4.5, packet_c-3.4.5.6 will be installed too.        
        Trotter list: packet_a-1.2.3.4, packet_b-2.3.4.5, packet_c-3.4.5.6, packet_d-4.5.6.7
        
        packet_a-1.2.3.4 depends on packet_b-2.3.4.5
        packet_a-1.2.3.4 depends on packet_c-3.4.5.6
        packet_b-2.3.4.5 replaces packet_d-4.5.6.7
        packet_c-3.4.5.6 replaces packet_d-4.5.6.7
        
        packet_d-4.5.6.7 is installed
        """
        
        packet_folder = "test_install29"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_name_c = "packet_c-3.4.5.6"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)
        packet_path_c = self.__get_packet_path(packet_folder, packet_name_c)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5", "packet_c-3.4.5.6", "packet_d-4.5.6.7"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))

        self.__mock_trotter.stubs().get_versions(eq("packet_b")).will(return_value(["2.3.4.5"]))
        self.__mock_trotter.stubs().get_versions(eq("packet_c")).will(return_value(["3.4.5.6"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_c"), eq("3.4.5.6")).will(return_value(packet_path_c))

        self.__storage.add(Packet(Meta("packet_d", "4.5.6.7", None, [], [], [])))

        packets_to_install = ("packet_a-1.2.3.4", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_d'), status=eq(Status.INSTALLED)).will(return_value([Packet(Meta('packet_d', '4.5.6.7', None, [], [], []))]))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(name=eq('packet_d'), status=eq(Status.INSTALLED)).will(return_value([Packet(Meta('packet_d', '4.5.6.7', None, [], [], []))]))",

                                   "remove(eq('packet_d-4.5.6.7'))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_b-2.3.4.5'))",
                                   "search(full_name=eq('packet_c-3.4.5.6'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "install(packet_path=string_contains('packet_c-3.4.5.6'))",
                                   "install(packet_path=string_contains('packet_a-1.2.3.4'))", )

        self.assert_install(packets_to_install, expected_actions)

    def test_install_failed1(self):
        """
        Packet - packet_b-2.3.4.5 will be installed.
        packet_b-2.3.4.5 depends on packet_a-1.2.3.4
        """
        
        packet_folder = "test_install30"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)

        
        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))

        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))

        packets_to_install = ("packet_a-1.2.3.4", "packet_b-2.3.4.5", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))", )

        self.__setup_virtual_docker_install_exception("packet_a-1.2.3.4")

        self.assert_failed_install(packets_to_install, expected_actions)

    def test_install_failed2(self):
        """
        Packet - packet_b-2.3.4.5 will be installed.
        packet_b-2.3.4.5 depends on packet_a-1.2.3.4
        """
        
        packet_folder = "test_install30"
        packet_name_a = "packet_a-1.2.3.4"
        packet_name_b = "packet_b-2.3.4.5"
        packet_path_a = self.__get_packet_path(packet_folder, packet_name_a)
        packet_path_b = self.__get_packet_path(packet_folder, packet_name_b)

        trotter_packet_list = ["packet_a-1.2.3.4", "packet_b-2.3.4.5"]
        self.__mock_trotter.stubs().get_packet_list().will(return_value(trotter_packet_list))

        self.__mock_trotter.stubs().get_versions(eq("packet_a")).will(return_value(["1.2.3.4"]))

        self.__mock_trotter.expects(once_or_never()).download(eq("packet_a"), eq("1.2.3.4")).will(return_value(packet_path_a))
        self.__mock_trotter.expects(once_or_never()).download(eq("packet_b"), eq("2.3.4.5")).will(return_value(packet_path_b))

        packets_to_install = ("packet_a-1.2.3.4", "packet_b-2.3.4.5", )
        expected_actions = ("search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_b-2.3.4.5'), status=eq(Status.INSTALLED)).will(return_value([]))",
                                   "search(full_name=eq('packet_a-1.2.3.4'), status=eq(Status.INSTALLED)).will(return_value([]))", )

        self.__setup_virtual_docker_install_exception("packet_b-2.3.4.5")

        self.assert_failed_install(packets_to_install, expected_actions)
        
    def __setup_mocks(self):
        cache = Cache(self.__cache_path)                
        select_strategy = LatestStrategy()
        
        self.__mock_trotter = Mock()        
        catalogue = Catalogue(self.__mock_trotter)

        self.__storage = MemoryStorage()
        self.__mock_docker = Mock()        
        self.__mock_docker.stubs().extract_storage().will(return_value(self.__storage))
        
        self.__gaffer = Gaffer(cache, self.__mock_docker, self.__mock_trotter, catalogue, select_strategy)

        self.__mock_virtual_docker = None
        self.__original_mock_virtual_docker_install = None
        self.__exceptional_packet_path = None
        
    def assert_failed_install(self, packets, expected_actions):
        mock_docker = self.__mock_docker
        
        for i in range(len(expected_actions)):
            action = expected_actions[i]

            if i == 0:
                eval("mock_docker.expects(once()).%s.id(i)" % action)
            else:
                eval("mock_docker.expects(once()).%s.id(i).after(i-1)" % action)

        self.assertRaises(GafferError, self.__gaffer.install, packets, virtual_docker=self.__mock_virtual_docker)
        self.__mock_docker.verify()

    def assert_install(self, packets, expected_actions):
        mock_docker = self.__mock_docker

        for i in range(len(expected_actions)):
            action = expected_actions[i]

            if i == 0:
                eval("mock_docker.expects(once()).%s.id(i)" % action)
            else:
                eval("mock_docker.expects(once()).%s.id(i).after(i-1)" % action)

        self.__gaffer.install(packets)
        self.__mock_docker.verify()

    def assert_install_fail(self, packets, expected_actions):
        mock_docker = self.__mock_docker

        for i in range(len(expected_actions)):
            action = expected_actions[i]

            if i == 0:
                eval("mock_docker.expects(once()).%s.id(i)" % action)
            else:
                eval("mock_docker.expects(once()).%s.id(i).after(i-1)" % action)

        self.assertRaises(GafferError, self.__gaffer.install, packets)
        self.__mock_docker.verify()

    def __setup_virtual_docker_install_exception(self, exceptional_packet_path):
        self.__exceptional_packet_path = exceptional_packet_path
        self.__mock_virtual_docker = DockerFactory().get_virtual_docker(self.__mock_docker)
        self.__original_mock_virtual_docker_install = self.__mock_virtual_docker.install
        self.__mock_virtual_docker.install = self.__mock_virtual_docker_install

    def __mock_virtual_docker_install(self, packet_path=None):
        if self.__exceptional_packet_path and self.__original_mock_virtual_docker_install:
            if not self.__exceptional_packet_path in packet_path:
                return self.__original_mock_virtual_docker_install(packet_path)

        raise DockerError("Testing virtual install failure! Failure path: %s" % packet_path)

    def __get_packet_path(self, packet_folder, packet_name):
        return os.path.join(self.__test_packets_path, packet_folder, packet_name + ".zip.ori") 

if __name__ == "__main__":
    suite = TestLoader().loadTestsFromTestCase(TestInstall)
    TextTestRunner(verbosity=2).run(suite)